<?php

namespace app\service;

use app\dao\MemberDao;
use think\facade\Log;
use think\Exception;

class MemberService
{
    private $memberDao;

    public function __construct()
    {
        $this->memberDao = new MemberDao();
    }

    // 获取成员信息
    public function getMemberInfo($memberId)
    {
        try {
            $member = $this->memberDao->getMemberById($memberId);
            if (!$member) {
                throw new Exception('成员不存在');
            }
            return $member;
        } catch (\Exception $e) {
            Log::error("获取成员信息失败: " . $e->getMessage());
            throw new Exception('系统异常，请稍后再试');
        }
    }

    // 创建成员
    public function createMember($data)
    {
        try {
            $member = $this->memberDao->addMember($data);
            if (!$member) {
                throw new Exception('创建成员失败');
            }
            return $member;
        } catch (\Exception $e) {
            Log::error("创建成员失败: " . $e->getMessage());
            throw new Exception('系统异常，请稍后再试');
        }
    }
}
